package top.i51213.fastaction.action.save;

import android.content.Context;
import android.net.Uri;
import android.view.View;

import java.util.List;
import java.util.zip.ZipOutputStream;

import top.i51213.fastaction.R;
import top.i51213.fastaction.action.BaseActonComponent;
import top.i51213.fastaction.action.Data;
import top.i51213.fastaction.action.DataType;
import top.i51213.fastaction.action.IntentType;
import top.i51213.fastaction.action.SameLast;
import top.i51213.fastaction.uri.MimeType;
import top.i51213.fastaction.uri.UriReader;
import top.i51213.fastaction.uri.UriWriter;
import top.i51213.fastaction.util.IOUtil;

public class SaveActionComponent extends BaseActonComponent implements SameLast {
    public SaveActionComponent(Context context) {
        super(context);
    }

    @Override
    protected Data makeOutputData() {
        List<Uri> list = getInputData().getUris();
        for (Uri uri : list) {
            try {
                UriReader uriReader=new UriReader(getContext(),uri);
                String displayName= uriReader.getDisPlayName();
                UriWriter uriWriter=new UriWriter(getContext(),displayName,MimeType.fromFileName(displayName),false);
                IOUtil.copyToAndClose(uriReader.openInputStream(), uriWriter.openOutputStream());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return getInputData();
    }

    @Override
    public int getImageResId() {
        return R.mipmap.save;
    }

    @Override
    public String getTitle() {
        return "保存";
    }

    @Override
    public String getInfo() {
        return "";
    }

    @Override
    public View getEditView() {
        return null;
    }

    @Override
    public void editViewDismissListener() {

    }

    @Override
    public Data getOutputData() {
        return getInputData();
    }

    @Override
    public IntentType getCurrentIntentType() {
        return IntentType.Save;
    }

    @Override
    public DataType getOutputDataType() {
        return null;
    }
}
